package com.prodog.usermodule.role.handler;

import com.prodog.command.annonations.Command;
import com.prodog.command.annonations.CommandBean;
import com.prodog.command.annonations.Interceptors;
import com.prodog.command.annonations.Iptor;
import com.prodog.command.entity.CommandResult;
import com.prodog.command.entity.GameCommand;
import com.prodog.command.entity.RoleGameCommand;
import com.prodog.usermodule.role.service.RoleInfoService;
import com.prodog.usermodule.user.dtos.CreateRoleDTO;
import com.prodog.usermodule.user.interceptor.NotRegistInterceptor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

@CommandBean(setName = "角色操作")
@NoArgsConstructor
public class RoleInfoHandler {
    @Autowired
    private RoleInfoService roleInfoService;

    @Command(value = "(创建角色|角色创建|新建角色|角色新建|创建|角创|cjjs)\\s+(.+?)\\s+([男女])", props = "null,roleName,sex")
    public CommandResult createRole(GameCommand command, CreateRoleDTO dto) {
        try {
            return roleInfoService.createRole(command, dto);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色创建失败");
        }
    }

    @Command(value = "(切换角色|角色切换|切角)\\s+(.+)", props = "null,roleName")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult changeRole(GameCommand command, String roleName) {
        try {
            return roleInfoService.changeRole(command, roleName);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色切换失败");
        }
    }

    @Command(value = "(角色列表|列表角色|所有角色|角色们|jslb|lbjs)")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult roleList(GameCommand command) {
        try {
            return roleInfoService.roleList(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色列表获取失败");
        }
    }

    @Command(value = "角色信息")
    @Interceptors(iptors = {
            @Iptor(value = NotRegistInterceptor.class)
    })
    public CommandResult roleInfo(GameCommand command) {
        try {
            return roleInfoService.roleInfo(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色信息获取失败");
        }
    }

    @Command(value = "(删除角色|角色删除|删角色|删角|scjs)\\s+(.+)", props = "null,roleName")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult deleteRole(GameCommand command, String roleName) {
        try {
            return roleInfoService.deleteRole(command, roleName);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色删除失败");
        }
    }

    @Command(value = "确认删除")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult confirmDelete(GameCommand command) {
        try {
            return roleInfoService.confirmDelete(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色删除失败");
        }
    }

    @Command(value = "取消删除")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult cancelDelete(GameCommand command) {
        try {
            return roleInfoService.cancelDelete(command);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，角色删除失败");
        }
    }

    @Command(value = {"选择职业\\s+(.+)"}, props = {"professionName"})
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult selectProfession(RoleGameCommand cmd, String professionName) {
        try {
            return roleInfoService.selectProfession(cmd, professionName);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，选择职业失败");
        }
    }

    @Command(value = "(角色属性|属性|jssx)")
    @Interceptors(iptors = {@Iptor(value = NotRegistInterceptor.class)})
    public CommandResult roleProp(RoleGameCommand cmd) {
        try {
            return roleInfoService.roleProp(cmd);
        } catch (Exception e) {
            e.printStackTrace();
            return CommandResult.failure("服务器错误，获取失败");
        }
    }
}
